/*
 * Copyright (c) 2022.  Liuhongbin All rights reserved.
 * @domain http://dkyx.cc
 * @author liuhongbin <514660094@qq.com>
 */

Vue.component('DkWxOauthDialog', {
    data() {
        return {
            show: true
        }
    },
    props: {
        title: {
            default: '',
            type: String
        },
        message: {
            default: '',
            type: String
        },
        cancelLink: {
            default: () => {
            },
            type: [Object, String]
        }
    },
    computed: {
        _message() {
            return this.message || '允许我们在必要的场景下,合理使用您的个人信息,并且充分保障您的合法权益'
        },
        _title() {
            return this.title || '获取你的昵称，头像'
        }
    },
    methods: {
        close(ac, done) {
            done(false)
        },
        clickNo() {
            if (this.cancelLink) {
                window.location.href = this.cancelLink
            } else {
                this.$toast('点击左上角关闭')
            }
        },
        clickOk() {
            dk.addUrlPara('force', 1)
        },
        // addUrlPara(name, value) {
        //     var currentUrl = window.location.href.split('#')[0];
        //     if (/\?/g.test(currentUrl)) {
        //         if (/name=[-\w]{4,25}/g.test(currentUrl)) {
        //             currentUrl = currentUrl.replace(/name=[-\w]{4,25}/g, name + "=" + value);
        //         } else {
        //             currentUrl += "&" + name + "=" + value;
        //         }
        //     } else {
        //         currentUrl += "?" + name + "=" + value;
        //     }
        //     if (window.location.href.split('#')[1]) {
        //         window.location.href = currentUrl + '#' + window.location.href.split('#')[1];
        //     } else {
        //         window.location.href = currentUrl;
        //     }
        // }
    },
    template: `
         <div class="oauth-dialog">
            <van-dialog v-model="show" :title="_title" :message="_message" show-cancel-button :before-close="close" @confirm="clickOk" @cancel="clickNo"/>
         </div>
    `
})


Vue.component('DkWxOauthOfficial', {
    props: {
        name: {
            default: '公众号名称',
            type: String
        },
        logo: {
            default: '',
            type: String
        },
        message: {
            default: '',
            type: String
        },
        cancelLink: {
            default: () => {
            },
            type: [Object, String]
        }
    },
    data() {
        return {
            show: true
        }
    },
    computed: {
        _message() {
            return this.message || '获得你的昵称、头像'
        },
        _logo() {
            return this.logo || ''
        }
    },
    methods: {
        clickNo() {
            if (this.cancelLink) {
                window.location.href = this.cancelLink
            } else {
                this.$toast('点击左上角关闭')
            }
        },
        clickOk() {
            dk.addUrlPara('force', 1)
        }
    },
    mounted() {
        console.log(this.cancelLink)
    },
    template: `
  <div class="oauth-official">
    <div class="header">
      <img :src="_logo" alt="">
      <span>{{ name }} </span>
      <span>申请获得</span>
    </div>
    <h2>以下权限</h2>
    <p style="display: flex;align-items: center;"><van-icon name="passed" ></van-icon>获得你的昵称、头像</p>
    <div class="footer">
      <van-button type="primary" class="btn ok" @click="clickOk">同意</van-button>
      <van-button class="btn no"  color="#eee" @click="clickNo">取消</van-button>
    </div>
  </div>
    `
})
